#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>



int 
main(int argc, char **argv)
{
    int rfd, wfd;
    char buf[BUFSIZ];

    if (1 == argc) {
	fprintf(stderr, "please, specify file name\n");
	exit(EXIT_FAILURE);
    }

    if ((wfd = open(argv[1], O_WRONLY | O_CREAT)) < 0) { 
	perror("failed to open file");
	exit(EXIT_FAILURE);
    }

    if ((rfd = open("/dev/ttyS0", O_RDONLY)) < 0) {
	perror("port open");
	exit(EXIT_FAILURE);
    }

    for(;;) {
	if (read(rfd, buf, BUFSIZ) < 0) {
	    perror("read");
	    exit(EXIT_FAILURE);
	}

	if (write(wfd, buf, BUFSIZ) < 0) {
	    perror("write");
	    exit(EXIT_FAILURE);
	}
    }
}
